package com.itheima.youdianda.controller;

import com.itheima.youdianda.common.Result;
import com.itheima.youdianda.domain.YddAdvpos;
import com.itheima.youdianda.service.YddAdvposService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.PublicKey;
import java.util.List;

/**
 * @author Hakuna Matata
 * @date 2022-09-07-9:33
 */
@RestController
@RequestMapping("ydd_advpos")
public class YddAdvPosController {

    @Autowired
    private YddAdvposService yddAdvposService;


    /**
     * 广告位列表  -- 分页
     *
     * @return
     */
    @GetMapping("list")
    public Result advList(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                          @RequestParam(value = "limit", required = false, defaultValue = "5") Integer limit,
                          String advposdesc, String advposname) {

        return yddAdvposService.advList(page, limit, advposdesc, advposname);

    }

    /**
     * 广告位修改
     *
     * @param yddAdvpos
     * @return
     */
    @PostMapping("update")
    public Result updateAdvPos(@RequestBody YddAdvpos yddAdvpos) {

        return yddAdvposService.updateAdvPos(yddAdvpos);
    }


    /**
     * 广告位列表 -- 全部
     */
    @GetMapping("all")
    public Result getAll() {
        List<YddAdvpos> yddAdvposList = yddAdvposService.list();
        return Result.ok(yddAdvposList);
    }

    /**
     * 广告位详情
     *
     * @return
     */
    @GetMapping("rowInfo")
    public Result getById(Integer id) {
        YddAdvpos yddAdvpos = yddAdvposService.getById(id);
        return Result.ok(yddAdvpos);
    }


    @PostMapping("add")
    public Result add(@RequestBody YddAdvpos yddAdvpos) {
        yddAdvpos.setDefaultData("1");
        yddAdvposService.save(yddAdvpos);
        return Result.ok("添加成功!");
    }

    @GetMapping("del")
    public Result delete(Integer id) {
        yddAdvposService.removeById(id);
        return Result.ok("删除成功!");
    }


}
